@extends('admin.layout.layout')
@section('title','分类管理')
@section('con')
<div id="page-wrapper">
    <div class="row">
        <div class="col-lg-12">
            <h1 class="page-header">分类列表</h1>
        </div>
        <!-- /.col-lg-12 -->
    </div>
    <!-- /.row -->
    <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
                <!-- /.panel-heading -->
             <div class="panel-body"> 
               <div class="dataTable_wrapper"> 
                <div id="dataTables-example_wrapper" class="dataTables_wrapper form-inline dt-bootstrap no-footer">
                 <div class="row">
                 <form action="{{url('/admin/cate/index')}}">
                  <div class="col-sm-6">
                   <div class="dataTables_length" id="dataTables-example_length">
                    <label>显示 
                        <select name="num" aria-controls="dataTables-example" class="form-control input-sm">
                            <option value="10" @if(!empty($list['num']) && $list['num'] == 10 ){ selected } @endif)>10</option>
                            <option value="25" @if(!empty($list['num']) && $list['num'] == 25 ){ selected } @endif)>25</option>
                            <option value="50" @if(!empty($list['num']) && $list['num'] == 50 ){ selected } @endif)>50</option>
                            <option value="100" @if(!empty($list['num']) && $list['num'] == 100 ){ selected } @endif)>100</option>
                        </select> 条</label>
                   </div>
                  </div>
                  <div class="col-sm-6">
                   <div id="dataTables-example_filter" class="dataTables_filter">
                    <label>搜索:<input name="keywords" value="{{ $list['keywords'] or ' ' }}" type="search" class="form-control input-sm" placeholder="" aria-controls="dataTables-example" /></label>
                    <button class="btn btn-primary" >查询</button>
                   </div>
                  </div>
                 </div>
                </form>
                 <div class="row">
                  <div class="col-sm-12">
                   <table id="dataTables-example" class="table table-striped table-bordered table-hover dataTable no-footer" role="grid" aria-describedby="dataTables-example_info"> 
                    <thead> 
                        <tr>
                            <th>分类Id</th>
                            <th>分类名称</th>
                            <th>所属分类</th>
                            <th>path路径</th>
                            <th>操作</th>
                        </tr>
                    </thead> 
                    <tbody> 
                    @foreach($cates as $k=>$v)
                         <tr class="gradeA" role="row"> 
                          <td class="sorting_1">{{$v->tid}}</td> 
                           
                          <td>{{$v->tname}}</td> 
                          <td class="center">{{$v->pid}}</td> 
                          <td class="center">{{$v->path}}</td> 
                          <td class="center">
                            <button class="btn btn-danger btn-sm delete-btn" type="button">
                                删除
                            </button>
                            <!-- <a href="{{url('/admin/user/edit',['id'=>$v->tid])}}" class="btn btn-warning">修改</a> -->
                            <a href="/admin/cate/edit?tid={{$v->tid}}" class="btn btn-warning btn-sm">修改</a>
                          </td> 
                         </tr>
                    @endforeach
                         
                    </tbody> 
                   </table>
                  </div>
                 </div>
                 <div class="row">
                    <!-- 分页 -->
                    
                 </div>
                </div> 
               </div> 
               <!-- /.table-responsive --> 
               
              </div>
                <!-- /.panel-body -->
            </div>
            <!-- /.panel -->
        </div>
        <!-- /.col-lg-12 -->
    </div>
</div>
@endsection
@section('js')
<script type="text/javascript">
    //解决csrf问题第二步 第一步在layout上加mate标签内容
    $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });

    //绑定单击事件
    $('.delete-btn').click(function(){
        var tid = $(this).parents('tr').find('.sorting_1').html();
        var btn = $(this);

        //发送ajax
        $.post('/admin/cate/delete',{tid:tid},function(data){
            if(data == 1){
                //删除成功
                alert('删除成功');
                btn.parents('tr').remove();
            }else{
                //删除失败
                alert('删除失败');
            }
        });
    })

</script>
@endsection